package Main;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileTimer
{

	private String filename;
	private long startTime;

	public void start()
	{
		startTime = System.currentTimeMillis();
		SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
		StringBuilder todayString = new StringBuilder(dateFormatter.format(new Date()));

		filename = "timer_" + todayString + "_" + startTime + ".txt";

	}

	public void stopAdd(String text)
	{
		PrintWriter out;
		try
		{
			out = new PrintWriter(new FileWriter(filename, true));
			out.write((System.currentTimeMillis() - startTime) + ": " + text + "\r\n");

			out.close();
			System.out.println("Saving " + filename);
		} catch (IOException e)
		{
			System.out.println("FileTimer: Saving error! '" + filename + "'");
		}

		startTime = System.currentTimeMillis();

	}
}
